package view.rules;

import java.awt.*;

import javax.swing.*;

import view.grammardevelopment.ViewSemanticsPanel;
import net.miginfocom.swing.MigLayout;

public class FeatureCopyPanel extends JPanel{
	
	ViewSemanticsPanel inputPanel;
	SubmitPanel submitPanel;
	private JPanel firstPanel;
	private JPanel ruleTypePanel;
	private JPanel structPanel;
	private JPanel featuresPanel;
	private JRadioButton featureCopyRButton;
	private JRadioButton featureSettingRButton;
	private JButton insertWordButton;
	private JButton addWordButton;
	private JButton notPresentButton;
	private JButton deleteButton;
	private JLabel structLabel;
	private JLabel featuresToCopy;
	private JLabel newNameForFeatureLabel;
	private JLabel defaultValueSourceLabel;
	private JLabel commentLabel;
	private JTextArea commentArea;
	private JSpinner structSpin;
	private JSpinner numberSpin;
	private JButton specifySourceButton;
	private JButton initialStructure;
	private JComboBox featuresToCopyCombo;
	private JComboBox defaultValueSourceCombo;
	private JTextField newNameForFeatureTextField;
	
	public FeatureCopyPanel(){
		this.setLayout(new MigLayout());
		
		initComponent();
		addComponent();
	}
	
	private void initComponent(){
		
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
				
		firstPanel = new JPanel();
		firstPanel.setLayout(new MigLayout());
		ruleTypePanel = new JPanel();
		ruleTypePanel.setBorder(BorderFactory.createTitledBorder("Type of Rule"));
		featureCopyRButton = new JRadioButton("Feature Copying");
		featureSettingRButton = new JRadioButton("Feature Setting");
		ruleTypePanel.add(featureCopyRButton);
		ruleTypePanel.add(featureSettingRButton);
		structPanel = new JPanel();
		structPanel.setLayout(new MigLayout());
		insertWordButton = new JButton("Insert Word");
		addWordButton = new JButton("Add Word");
		notPresentButton = new JButton("Not Present");
		deleteButton = new JButton("Delete");
		structLabel = new JLabel("Structure:");
		SpinnerModel sm = new SpinnerNumberModel(0, 0, 100, 1);
		structSpin = new JSpinner(sm);
		structSpin.setMinimumSize(new Dimension(100, 20));
		specifySourceButton = new JButton("Specify Source");
		initialStructure = new JButton("Initialize this Structure");
		
		inputPanel = new ViewSemanticsPanel("", "", "");
		inputPanel.setPreferredSize(new Dimension(((int)screenSize.getWidth() - 50) , (int)screenSize.getHeight() - 300));
		
		featuresPanel = new JPanel();
		featuresPanel.setLayout(new MigLayout());
		featuresPanel.setBorder(BorderFactory.createTitledBorder("Features to be Copied"));
		featuresPanel.setPreferredSize(new Dimension(((int)screenSize.getWidth() - 50) , (int)screenSize.getHeight() - 700));
		SpinnerModel spinModel = new SpinnerNumberModel(0, 0, 100, 1);
		numberSpin = new JSpinner(spinModel);
		numberSpin.setMinimumSize(new Dimension(50, 20));
		featuresToCopy = new JLabel("Feature to Copy:");
		featuresToCopyCombo = new JComboBox();
		featuresToCopyCombo.setMinimumSize(new Dimension(406, 20));
		newNameForFeatureLabel = new JLabel("New Name for Copied Feature:");
		newNameForFeatureTextField = new JTextField(50);
		defaultValueSourceLabel = new JLabel("Default Value if Source NOT Available: ");
		defaultValueSourceCombo = new JComboBox();
		defaultValueSourceCombo.setMinimumSize(new Dimension(406, 20));
		
		commentLabel = new JLabel("Comment:");
	    commentArea = new JTextArea();
	    commentArea.setMinimumSize(new Dimension((int)screenSize.getWidth() - 200, (int)screenSize.getHeight() - 700));
		
	    submitPanel = new SubmitPanel();
		
	}
	
	private void addComponent(){
		
		addToFirstPanel();
		JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, firstPanel, inputPanel);
		splitPane.setOneTouchExpandable(true);
		add(splitPane, "wrap");
		addToFeaturesPanel();
		add(featuresPanel, "wrap");
		add(commentLabel, "wrap");
		add(commentArea, "wrap");
		add(submitPanel);
		
	}
	
	private void addToFirstPanel(){
		
		firstPanel.add(ruleTypePanel);
		addToStructPanel();
		firstPanel.add(structPanel);
	}
	
	private void addToStructPanel(){
		structPanel.add(insertWordButton);
		structPanel.add(addWordButton);
		structPanel.add(notPresentButton);
		structPanel.add(deleteButton);
		structPanel.add(structLabel, "gapleft 20");
		structPanel.add(structSpin);
		structPanel.add(specifySourceButton, "gapleft 20");
		structPanel.add(initialStructure);
	}
	
	private void addToFeaturesPanel(){
		featuresPanel.add(numberSpin, "wrap");
		featuresPanel.add(featuresToCopy);
		featuresPanel.add(featuresToCopyCombo, "wrap");
		featuresPanel.add(newNameForFeatureLabel);
		featuresPanel.add(newNameForFeatureTextField, "wrap");
		featuresPanel.add(defaultValueSourceLabel);
		featuresPanel.add(defaultValueSourceCombo);
	}

}
